package app.cn.com.school.fragment

import android.content.ContentValues
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import app.cn.com.school.R
import app.cn.com.school.activity.*
import app.cn.com.school.adapter.UsedCountAdapter
import app.cn.com.school.adapter.WeGoodsAdapter
import app.cn.com.school.databinding.FragmentUsedBinding

/**
 * Created by Administrator on 2017/11/1 0001.
 */
class UsedFragment : BaseFragment<FragmentUsedBinding>() {
    override fun initBindingVar() {
    }

    var adapterCount: UsedCountAdapter? = null
    var adapterGoods: WeGoodsAdapter? = null
    var moreList = ArrayList<ContentValues>()

    private var mParam1: String? = null
    private var mParam2: String? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (arguments != null) {
            mParam1 = arguments.getString(ARG_PARAM1)
            mParam2 = arguments.getString(ARG_PARAM2)
        }
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        initBinding(R.layout.fragment_used, container)
        mView = binding.root
        initView()
        return super.onCreateView(inflater, container, savedInstanceState)
    }


    private fun initView() {
        moreList.add(ContentValues())
        moreList.add(ContentValues())
        moreList.add(ContentValues())
        moreList.add(ContentValues())
        moreList.add(ContentValues())
        moreList.add(ContentValues())
        moreList.add(ContentValues())
        moreList.add(ContentValues())

        if (adapterCount == null) {
            adapterCount = UsedCountAdapter(context, moreList)
            binding.usedContent.adapter = adapterCount
        }

        if (adapterGoods == null) {
            adapterGoods = WeGoodsAdapter(context, moreList)
            binding.usedGird.adapter = adapterGoods
        }
        //发布
        binding.usedPush.setOnClickListener {
            startActivity(Intent(context, PublishActivity::class.java))
        }

        //选择城市
        binding.choseCity.setOnClickListener { startActivity(Intent(context, SortActivity::class.java).putExtra("type", "1")) }

        //消息
        binding.usedNews.setOnClickListener { startActivity(Intent(context, NewsActivity::class.java)) }

        //查看详情
        binding.usedGird.setOnItemClickListener { parent, view, position, id ->
            startActivity(Intent(context,IntegralActivity::class.java).putExtra("type","4"))
        }

        binding.usedContent.setOnItemClickListener { parent, view, position, id ->
            startActivity(Intent(context,UsedItemDetailsActivity::class.java))
        }

    }

    companion object {
        private val ARG_PARAM1 = "param1"
        private val ARG_PARAM2 = "param2"
        fun newInstance(param1: String, param2: String): UsedFragment {
            val fragment = UsedFragment()
            val args = Bundle()
            args.putString(ARG_PARAM1, param1)
            args.putString(ARG_PARAM2, param2)
            fragment.arguments = args
            return fragment
        }
    }

}